package com.mt.api.modules.controller;

import com.mt.common.response.WebResponse;
import com.mt.common.response.WebResponseUtils;
import com.mt.log.annotation.Log;
import com.mt.api.modules.domain.bo.AppOutStorePageBo;
import com.mt.api.modules.domain.bo.OutStoreCancelBo;
import com.mt.api.modules.domain.vo.OutStoreDetailVo;
import com.mt.api.modules.service.IOutStoreDetailService;
import com.mt.api.modules.service.IOutStoreService;
import com.mt.api.util.ParamsValid;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: plover
 * @Date: 2022/05/31 11:50
 * @Description:
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "出库管理")
@RequestMapping("/app/out/store")
public class OutStoreController {

    private final IOutStoreDetailService outStoreDetailService;
    private final IOutStoreService outStoreService;

    @GetMapping("/page")
    @ApiOperation(value = "", notes = "配货单分页列表接口", httpMethod = "GET")
    public WebResponse getOutStorePage(AppOutStorePageBo bo) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("pageNum不能为空", bo.getPageNum())
                .validNotNull("pageSize不能为空", bo.getPageSize());
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return outStoreDetailService.getOutStorePage(bo);
    }

    @GetMapping("/detail")
    @ApiOperation(value = "", notes = "出库单详情接口", httpMethod = "GET")
    public WebResponse<OutStoreDetailVo> getOutStoreDetail(Integer outStoreId) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("outStoreId", outStoreId);
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return outStoreDetailService.getOutStoreDetail(outStoreId);
    }

    @PostMapping("/cancel")
    @Log("出库单撤销")
    @ApiOperation(value = "", notes = "出库单撤销接口", httpMethod = "POST")
    public WebResponse cancelOutStore(@RequestBody OutStoreCancelBo bo) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("出库单id不能为空", bo.getOutStoreId());
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return outStoreService.cancelOutStore(bo);
    }

}
